package com.zcoj.controller.User.training;

import com.zcoj.core.model.ApiResponse;
import com.zcoj.core.model.PageWrap;
import com.zcoj.pojo.Dto.Training;
import com.zcoj.pojo.Vo.TrainingAuthVo;
import com.zcoj.security.dto.LoginUser;
import com.zcoj.service.TrainingService;
import com.zcoj.util.RedisCaches;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 接口
 * @author 剩xia的盛夏
 * @date 2023/02/24 16:16
 */
@RestController
@RequestMapping("/training")
@Api(tags = "接口")
public class TrainingController  {

    @Autowired
    private TrainingService trainingService;

    @Autowired
    private RedisCaches redisCaches;




    @PostMapping("/findPageVo")
    @ApiOperation("分页查询")
    public ApiResponse findPageVo(@RequestBody PageWrap<Training> pageWrap) {
        LoginUser loginUser = redisCaches.getLoginUser();
        if(!(loginUser.getPermission().contains("admin")||loginUser.getPermission().contains("super_admin")||loginUser.getPermission().contains("training_admin"))){
            pageWrap.getModel().setStatus(1);
        }else {
            pageWrap.getModel().setStatus(null);
        }
        return ApiResponse.success(trainingService.findPageVo(pageWrap));
    }

    /**
     * 通过ID查询
     * @author 剩xia的盛夏
     * @date 2023/02/24 16:16
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询")
    public ApiResponse finById(@PathVariable Integer id) {
        return ApiResponse.success(trainingService.findById(id));
    }



    @ApiOperation("查询训练的权限")
    @PostMapping("/getTrainingAuth")
    public ApiResponse getTrainingAuth(@RequestBody TrainingAuthVo trainingAuthVo){
        return trainingService.getTrainingAuth(trainingAuthVo);
    }
}
